<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
        	height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
        }
        .content {
        	height: 100%;
        	padding: 0 0;
        	display: -webkit-box;
        	-webkit-box-align: end;
        }
        .main {
        	width: 100%;
        	background-color: #fff;
        	overflow: hidden;
        }
        .main .main_t {
        	height: 50px;
        	line-height: 50px;
        	font-size: 16px;
        	color: #333;
        	text-align: center;
        	border-bottom: 1px solid #e8e8e8;
        }
        .main .main_b {
        	padding: 15px;
            padding-bottom: 0;
            text-align: center;
        }
        .main_b img{
            margin: 0 auto;
            display: inline-block;
            width: 200px;
        }
        .btn_box{
            line-height: 60px;
            color: #40afe2;
        }
        .main .main_t.cancel{
            color: #e62442;
        }
    </style>
</head>
<body>
	<div class="content" id="dialog">
	    <div class="main">
            <div tapmode onclick="toChooseMap('gMap',this);" class="main_t">谷歌地图</div>
	    	<div tapmode onclick="toCancel();" class="main_t cancel">取消</div>
	    </div>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){

        $(document.body).on('touchend', function(e) {
            var dialog = $('#dialog')[0];
            if (!$.contains(dialog, e.target)) {
                $('#dialog').removeClass('in');
                api.closeFrame();
            }
        });
    };

    // 取消
    function toCancel() {
        api.closeFrame();
    }

    function toChooseMap (_type,_this) {
        var _that = $(_this);
        var navigator = api.require('navigator');
        navigator.installed({
            target: _type
        }, function(ret, err) {
            if (ret.status) {
                fnDoNav(_type);
            } else {
                toast('请先安装'+_that.text());
            }
        });
    };

    function fnDoNav (_type) {
        var destinationLng = api.pageParam.destinationLng;
        var destinationLat = api.pageParam.destinationLat;
        var staffLng = api.pageParam.staffLng;
        var staffLat = api.pageParam.staffLat;
        
        var navigator = api.require('navigator');
        if(_type == 'aMap'){
            navigator.aMapNavigation({
                end: {
                    lon: destinationLng,
                    lat: destinationLat
                },
                dev: 0,
                strategy: 'fast'
            });
        }else if(_type == 'bMap'){
            navigator.bMapNavigation({
                end: { // 终点信息.
                    lon: destinationLng, // 经度
                    lat: destinationLat, // 纬度
                    name: ''
                },
                mode: 'driving'
            });
        }else if(_type == 'gMap'){
            navigator.gMapNavigation({
                start: {
                    lon: staffLng,
                    lat: staffLat
                },
                end: {
                    lon: destinationLng,
                    lat: destinationLat
                },
                mode: 'driving'
            });
        }
        
    };

</script>
</html>